package cn.stylefeng.guns.modular.school.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.school.entity.TripOrderInfo;
import cn.stylefeng.guns.modular.school.mapper.TripOrderInfoMapper;
import cn.stylefeng.guns.modular.school.model.params.TripOrderInfoParam;
import cn.stylefeng.guns.modular.school.model.result.TripOrderInfoResult;
import  cn.stylefeng.guns.modular.school.service.TripOrderInfoService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 行程预约信息 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-04-12
 */
@Service
public class TripOrderInfoServiceImpl extends ServiceImpl<TripOrderInfoMapper, TripOrderInfo> implements TripOrderInfoService {

    @Override
    public void add(TripOrderInfoParam param){
        TripOrderInfo entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TripOrderInfoParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TripOrderInfoParam param){
        TripOrderInfo oldEntity = getOldEntity(param);
        TripOrderInfo newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TripOrderInfoResult findBySpec(TripOrderInfoParam param){
        return null;
    }

    @Override
    public List<TripOrderInfoResult> findListBySpec(TripOrderInfoParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TripOrderInfoParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TripOrderInfoParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TripOrderInfo getOldEntity(TripOrderInfoParam param) {
        return this.getById(getKey(param));
    }

    private TripOrderInfo getEntity(TripOrderInfoParam param) {
        TripOrderInfo entity = new TripOrderInfo();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
